namespace DotNetNuke.UI.WebControls
{
    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    internal class DNNMenuWriter : WebControl, IDNNMenuWriter
    {
        private DNNMenu m_objMenu;

        protected override void RenderChildren(HtmlTextWriter writer)
        {
            IEnumerator enumerator=null;
            try
            {
                enumerator = this.m_objMenu.MenuNodes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ((MenuNode) enumerator.Current).Render(writer);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    ((IDisposable) enumerator).Dispose();
                }
            }
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            string str = "DNNMenu ";
            if (this.m_objMenu.SelectedMenuNodes.Count == 0)
            {
                if (Strings.Len(this.m_objMenu.MenuBarCssClass) > 0)
                {
                    str = str + this.m_objMenu.MenuBarCssClass;
                }
            }
            else if (Strings.Len(this.m_objMenu.MenuCssClass) > 0)
            {
                str = str + this.m_objMenu.MenuCssClass;
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            writer.AddAttribute(HtmlTextWriterAttribute.Class, str);
            writer.AddAttribute(HtmlTextWriterAttribute.Name, this.m_objMenu.UniqueID);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.m_objMenu.UniqueID.Replace(":", "_"));
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            this.RenderChildren(writer);
            writer.RenderEndTag();
        }

        public void RenderMenu(HtmlTextWriter writer, DNNMenu Menu)
        {
            this.m_objMenu = Menu;
            this.RenderControl(writer);
        }
    }
}

